package service.clazz.strategy;

import constant.table.ClazzConstact;
import entity.table.TableDto;
import entity.table.TableFileDto;
import entity.table.TableInfoDto;
import enums.table.ClazzTypeEnum;
import enums.table.InitImportEnum;
import service.clazz.interfaces.ClazzStrategy;

import java.util.ArrayList;
import java.util.List;

/**
 * 实体类
 */
public class ClazzDaoStrategy extends ClazzStrategy {

    @Override
    public TableFileDto enerateStrategy(List<TableDto> list, TableInfoDto table) {
        TableFileDto tableFileDto = new TableFileDto();
        tableFileDto.setFileName(table.getTableNameCamel(ClazzTypeEnum.DAO)+".java");
        tableFileDto.setContext(this.bringClazz(list, table));
        return tableFileDto;
    }

    /**
     * 生成类
     */
    public String bringClazz(List<TableDto> list, TableInfoDto table) {
        StringBuilder str = new StringBuilder();

        // 类路径
        str.append(super.bringPackage(table.getDaoPackaging()));
        // 类引用
        str.append(super.bringImport(this.importList(table)));
        // 类内容
        str.append(super.bringBody(ClazzTypeEnum.DAO, table.getTableNameCamel(), this.body(table)));
        // 输出
        return str.toString();
    }

    private List<String> importList(TableInfoDto table) {
        List<String> list = InitImportEnum.initEntityList();
        list.add(table.getEntityPackaging()+".*");
        return list;
    }

    private String body(TableInfoDto table) {
        return super.codeTemple("Dao", table);
    }
}
